﻿<script src="../WFRes/_Scripts/jquery/ajaxfileupload.js"></script>
<style>
    .tableList .tableLeft {
        width: 160px;
        padding-left: 0px;
    }
</style>
<script>
    //qiancheng
    var pageData = {
        ReportPackage: { ReportPackage: {}, IsCover:false },//报表页模型
        LanData: $.Languages
    }

    $(function () {
        // debugger
        var ParentID = getUrlParam("ParentID");
        var ParentCode = getUrlParam("ParentCode");
        pageData.ReportPackage.ParentID = ParentID;
        pageData.ReportPackage.ParentCode = ParentCode;

        //获取目录名称
        GetPrentFloderName(ParentID);

        DocumentReady();

        var model = new Vue({
            el: "#content",
            data: pageData,
            methods: {
                format: function (template, content) {
                    return $.format(template, content);
                }
            }
        });
    });

    GetPrentFloderName = function (ParentID) {
        var actionUrl = $.Controller.WorkflowPackageHandler.GetParentFolderName;
        $.ajax({
            url: actionUrl,
            type: "get",
            data: {ParentID:ParentID},
            success: function (result) {
                $("#lblcatalog").text(result);
            }
        });
    }

    DocumentReady = function () {
        $("#H3ToolBar").AspLinkToolBar();
        $(".H3Panel").BuildPanel();
       
    };


    Upload = function () {
        // debugger
        if (CheckFile()) {
            var uploadUrl = $.Controller.ReportFolder.UpLoad;
            $.ajaxFileUpload({
                url: uploadUrl,
                fileElementId: "btnFileUpload",
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.Success) {
                        pageData.ReportPackage = data.Extend;
                       // pageData.ReportPackage.XMLString = encodeURIComponent(pageData.ReportPackage.XMLString);

                        var ParentID = getUrlParam("ParentID");
                        var ParentCode = getUrlParam("ParentCode");
                        pageData.ReportPackage.ParentID = ParentID;
                        pageData.ReportPackage.ParentCode = ParentCode;
                       
                        //显示服务编码标签,上传标签隐藏
                        $("#CodeInfoPanel").show();
                        $("#UploadPanel").hide();

                        //设置按钮可用
                        $("#btnImport").removeAttr("disabled").attr("enabled","true");
                        $("#btnImport").children().removeClass("l-toolbar-item-disable");

                        $("#btnReset").removeAttr("disabled").attr("enabled", "true");
                        $("#btnReset").children(":first").removeClass("l-toolbar-item-disable");

                    } else {
                        $.H3Dialog.Warn({ content: $.Lang(data.Message) });
                    }
                }
            });
        }
    }

    CheckFile = function () {
        var fileVal = $("#btnFileUpload").val();
        if (fileVal == "") {
            $.H3Dialog.Warn({ content: $.Lang("WorkflowPackageImport.MasterData_Mssg10") });
            return false;
        }
        if (fileVal.toLowerCase().indexOf(".xml") < 0) {
            $.H3Dialog.Warn({ content: $.Lang("WorkflowPackageImport.MasterData_Mssg2") });
            return false;
        }
        return true
    }

    BeforeImport = function () {
        $("input[txtType='codeinfo']").each(function () {
            //校验表单编码，不能以数字开始
            if ($(this).attr("codeinfo") == "BizSheet") {
                var startWithNum = /^[0-9]+[\s\S]*$/;
                if (startWithNum.test($(this).val())) {
                    $.H3Dialog.Warn({ content: "WorkflowPackageImport.PackageImportHandler_FormCode" });
                    return false;
                }
            }
        });

        var Code = "";
        var Name = "";
        var flag = false;
         
        //是否覆盖
        pageData.ReportPackage.IsCover = $("span[txttype='ckIsCover']").find("input[type='checkbox']")[0].checked;

        //保存编码
        Code = pageData.ReportPackage.ReportsPackage.Code = $("#txtPackageCode").val();
        if (Code == "") { flag = true;}

        //保存显示名称
        Name = pageData.ReportPackage.ReportsPackage.Name = $("#txtPackageName").val();

       
        if (flag) {
            $.H3Dialog.Warn({ content: $.Lang("msgGlobalString.CodeOrNameNotNull") });
            return false;
        }
        return true;
    }

    Import = function () {
        if (BeforeImport()) {
            var importUrl = $.Controller.ReportFolder.Import;//导入
            var formData = JSON.stringify(pageData.ReportPackage);
            $.ajax({
                url: importUrl,
                type: 'post',
                dataType: "json",
                data: {formData:formData},
                async: false,//同步执行
                success: function (result) {
                    if (result.Success) {
                        $.H3Dialog.Success({ content: $.Lang(result.Message) });

                        //更新节点 top.ReloadNode('ParentID')
                        top.ReloadNode(pageData.ReportPackage.ParentID);
                        parent.H3DialogManger.Close(); //关闭当前对话框
                    } else {
                        $.H3Dialog.Warn({ content: $.Lang(result.Message) });
                    }
                }
            });
        }
    }
    oncheckeds = function () {
        var checked = $("span[txttype='ckIsCover']").find("input[type='checkbox']")[0].checked;
        if (checked) {
            $("#txtPackageCode").parent().parent().hide();
            $("#txtPackageCode").val(pageData.ReportPackage.ReportsPackage.Code);
        } else {
            $("#txtPackageCode").parent().parent().show();
        }
       
    }
    Reset = function ()
    {
        pageData.ReportPackage.ReportPackage = {};
       // pageData.WorkflowPackage.BizSchema = {};
       // pageData.WorkflowPackage.BizSheets = [];

        $("#CodeInfoPanel").hide();
        $("#UploadPanel").show();
    }

    Format = function (template, content) { $.format(template, content); }
</script>
<div id="H3ToolBar">
    <a id="btnImport" href="javascropt:void(0)" onclick="Import()" data-icon="fa fa-upload" data-lang="GlobalButton.Import"></a>
    <a id="btnReset" href="javascropt:void(0)" onclick="Reset();" data-icon="fa fa-upload" data-lang="H3TreeTools.Reload"></a>
</div>
<input type="hidden" id="CodeInfo"  />
<input type="hidden" id="fileName" />
<input type="hidden" id="ckIsCover" />

<div id="UploadPanel">
    <div class="H3Panel">
        <table>
            <tr>
                <td data-lang="WorkflowPackageImport.PackageImportHandler_Catalog"></td>
                <td>
                    <label id="lblcatalog" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="file" id="btnFileUpload" name="btnFileUpload" />
                    <a id="btnUpLoad" href="javascript:Upload();" data-lang="BizServiceHandler.Upload"></a>

                </td>
            </tr>
        </table>
    </div>
</div>


 <div id="CodeInfoPanel" style="display:none">
    <div class="H3Panel">
        <span data-lang="WorkflowPackageImport.MasterData_Mssg4"></span>
        <table id="CodeTable">
            <tr>
                <td data-lang="msgGlobalString.IsCover"></td>
                <td>
                    <span txttype="ckIsCover">
                        <input id="IsCover" type="checkbox" onchange="oncheckeds()" model="WorkflowPackage.IsCover" />
                        <label for="IsCover" data-lang="msgGlobalString.IsCover"></label>
                    </span>
                </td>
                <td data-lang="msgGlobalString.CoverMsg"></td>
            </tr>
            <!-- 报表页编码-->
            <tr>
                <td id="codeDisplay" data-lang="H3TreeTools.coding"></td>
                <td style="width:300px">
                    <input type="text" id="txtPackageCode" codeinfo="{{ReportPackage.ReportsPackage.CodeType}}" code="" value="{{ReportPackage.ReportsPackage.Code}}" />
                </td>
                <td style="color:Red">*</td>
            </tr>
            <!-- 报表页名称-->
            <tr>
                <td id="nameDisplay" data-lang="H3TreeTools.displayname"></td>
                <td style="width:300px">
                    <input type="text" id="txtPackageName" codeinfo="{{ReportPackage.ReportsPackage.CodeType}}" code="" value="{{ReportPackage.ReportsPackage.Name}}" />
                </td>
                <td style="color:Red">*</td>
            </tr>
        </table>
    </div>
</div>
